package org.theSeed.springBase.utils;

import cn.hutool.extra.spring.SpringUtil;
import org.theSeed.springBase.config.ThreadCacheHolder;
import org.theSeed.springBase.contract.ThreadCache;

/**
 * 线程缓存工具
 */
public class ThreadCacheUtil{
    /**
     * 获取threadCache持有者
     * @return
     */
    private static ThreadCacheHolder getThreadCacheHolder(){
        return SpringUtil.getBean(ThreadCacheHolder.class);
    }

    /**
     * 获取数据
     * @param type
     * @return
     * @param <T>
     */
    public static  <T> T getData(String type){
        return getThreadCacheHolder().getData(type);
    }

    /**
     * 设置数据
     * @param data
     * @param type
     * @param <T>
     */
    public static  <T> void setData(T data,String type){
        getThreadCacheHolder().setData(data,type);
    }

    /**
     * 清除数据
     * @param type
     * @param <T>
     */
    public static  <T> void clear(String type){
        getThreadCacheHolder().clear(type);
    }

    /**
     * 获取指定实现
     * @param type
     * @return
     * @param <T>
     */
    public static  <T> ThreadCache<T> getThreadCache(String type){
        return getThreadCacheHolder().getThreadCache(type);
    }
}
